import {
  createRouter,
  createWebHashHistory
} from "vue-router";
import Layout from "../layouts/index.vue";

/**
 * Note: 子菜单仅当路由的children.length >= 1时才出现
 *
 * hidden: true                   设置为true时路由将显示在sidebar中(默认false)
 * alwaysShow: true               如果设置为true则总是显示在菜单根目录
 *                                如果不设置alwaysShow, 当路由有超过一个子路由时,
 *                                将会变为嵌套模式, 否则不会显示根菜单
 * redirect: noRedirect           如果设置noRedirect时，breadcrumb中点击将不会跳转
 * name:'router-name'             name用于<keep-alive> (必须设置!!!)
 * meta : {
    roles: ['admin','editor']    页面可访问角色设置 
    title: 'title'               sidebar和breadcrumb显示的标题 
    icon: 'svg-name'/'el-icon-x' sidebar中显示的图标
    breadcrumb: false            设置为false，将不会出现在面包屑中
    activeMenu: '/example/list'  如果设置一个path, sidebar将会在高亮匹配项
  }
 */
export const routes = [{
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [{
      path: '/redirect/:path(.*)',
      component: () => import('views/redirect/index.vue')
    }]
  },
  {
    path: "/",
    redirect: "/home",
    component: Layout,
    meta: {
      title: "导航",
      icon: "el-icon-s-home"
    },
    children: [{
      path: "home",
      component: () => import("views/home.vue"),
      name: "Home",
      meta: {
        title: "首页",
        icon: "el-icon-s-home"
      },
      children: [{
        path: ":id",
        component: () => import("views/detail.vue"),
        name: "Detail",
        hidden: true,
        meta: {
          title: "详情",
          icon: "el-icon-s-home",
          activeMenu: "/home",
        }
      }]
    }]
  },
  {
    path: "/users",
    component: Layout,
    meta: {
      title: "用户管理",
      icon: "el-icon-user-solid",
    },
    redirect: '/users/list',
    children: [{
        path: "list",
        component: () => import("views/users/list.vue"),
        meta: {
          title: "用户列表",
          icon: "el-icon-document",
        },
      },
      {
        path: "create",
        component: () => import("views/users/create.vue"),
        hidden: true,
        meta: {
          title: "创建新用户",
          activeMenu: "/users/list",
        },
      },
      {
        path: "edit/:id(\\d+)",
        name: "userEdit",
        component: () => import("views/users/edit.vue"),
        hidden: true,
        meta: {
          title: "编辑用户信息",
          activeMenu: "/users/list",
        },
      },
    ],
  },
  {
    path: '/guide',
    component: Layout,
    redirect: '/guide/index',
    meta: {
      title: 'Guide',
      icon: 'el-icon-s-promotion',
    },
    children: [{
      path: 'index',
      name: 'Guide',
      meta: {
        title: 'Guide',
        noCache: true
      },
      component: () => import('views/guide/index.vue'),
    }]
  },
  {
    path: '/external-link',
    component: Layout,
    meta: { icon: 'el-icon-position' },
    children: [
      {
        path: 'https://panjiachen.github.io/vue-element-admin/#/dashboard',
        meta: { title: 'External Link', icon: 'el-icon-position' }
      }
    ]
  },
];
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}
const router = createRouter({
  history: createWebHashHistory(),
  routes,
});
export default router